<?php
namespace Weixin\Controller;
use Think\Controller;
class UserController extends BaseController{
	//初始化
	public function bind(){
		//【车还还】您的验证码是#code#。如非本人操作，请忽略本短信,54207
		if(empty($_POST)){
			$this->display();
		}else{
			$msg = array('returnCode'=>'0','returnInfo'=>'ok','returnUrl'=>'/Weixin/User/index');
			if(session('uid')){
				//先检测手机号与验证码是否关联
				$tpl_value= M('Sms')->where("mob='%s'",I('post.phone'))->order('id desc')->getField('tpl_value');
				$code = str_replace('#code#=','',$tpl_value);
				if($code == I('post.phone_code')){
					$data = array('mobile'=>I('post.phone'),'card'=>I('post.card'),'name'=>I('post.name'),
						'card'=>I('post.card'),'eaccount'=>I('post.eaccount'));
					$where = array('user_id'=>session('uid'));
					$uid = M('User')->where($where)->save($data);
					if($uid === false){
						$msg = array('returnCode'=>'1','returnInfo'=>'系统异常');
					}
				}else{
					$msg = array('returnCode'=>'1','returnInfo'=>'手机验证码不正确');
				}
			}else{
				$msg = array('returnCode'=>'1','returnInfo'=>'请在微信登录');
			}
			echo json_encode($msg);
		}
	}


    /** 
	 *  
	 * 验证码生成 
	 */  
	public function verify(){  
	    $Verify = new \Think\Verify();  
	    $Verify->fontSize = 20;  
	    $Verify->length   = 4;  
	    //$Verify->useNoise = false;  
	    $Verify->codeSet = '0123456789';  
	    //$Verify->imageW = 130;  
	    //$Verify->imageH = 50;  
	    //$Verify->expire = 600;  
	    $Verify->entry();  
	}

	public function index(){
		$user = M('User')->where("user_id='%d'",session('uid'))->find();
		$this->assign('user',$user);
		$this->display();
	}

	public function person(){
		if(empty($_POST)){
			$user = M('User')->where("user_id='%d'",session('uid'))->find();
			$this->assign('user',$user);
			$this->display();
		}else{
			$msg = array('returnCode'=>'0','returnInfo'=>'ok','returnUrl'=>'/Weixin/User/index');
			if(session('uid')){
				$data = array('mobile'=>I('post.phone'),'card'=>I('post.card'),'name'=>I('post.name'),
					'card'=>I('post.card'),'eaccount'=>I('post.eaccount'));
				$where = array('user_id'=>session('uid'));
				$uid = M('User')->where($where)->save($data);
				if($uid === false){
					$msg = array('returnCode'=>'1','returnInfo'=>'系统异常');
				}
			}else{
				$msg = array('returnCode'=>'1','returnInfo'=>'请在微信登录');
			}
			echo json_encode($msg);
		}	
	}
}